<?php
/**
 * Created by 784855684@qq.com.
 * User: linzh
 * Date: 8/2/17
 * Time: 3:07 PM
 */


namespace inframe\test\controller;

use inframe\library\excel\Export as E;
use inframe\library\excel\Import;
use inframe\library\ExcelIO;

class export
{

    public function showImport()
    {
        $path = IN_PUBLIC_URL . '/index/import';

        echo <<<endline
<html>
<body>
<form action="$path" method="post" enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="upload_file" /> 
<br />
<input type="submit" name="submit" value="Submit" />
</form>
</body>
</html>
endline;
    }

    public function import()
    {
        $upload_file = ExcelIO::getImportFile('upload_file');
        $engine = new Import($upload_file);
        $data = $engine->setMap([
            'id' => [
                'colnm' => 'A',
                'text' => 'ID',
            ],
            'phone' => [
                'colnm' => 'B',
                'text' => '帐号',
            ],
            'role' => [
                'colnm' => 'C',
                'text' => '角色',
            ],
            'name' => [
                'colnm' => 'D',
                'text' => '姓名',
            ],
            'status' => [
                'colnm' => 'E',
                'text' => '状态',
            ],
            'store' => [
                'colnm' => 'F',
                'text' => '门店',
            ],
        ])->fetch();
        dumpout($data);
    }

    public function export()
    {
        $export = new E();
        ExcelIO::export('djshdjshaj中文', $export->setTitle('中文标题')->setHead([
            'id' => [
                'title' => 'ID',
                'type' => E::TYPE_STR,
                'align' => E::ALI_LEFT,
                'width' => 14,
            ],
            'name' => [
                'title' => '中文title',
                'type' => E::TYPE_STR,
                'align' => E::ALI_RIGHT,
                'width' => 25,
            ],
        ])->setBody([
            [
                'id' => '1',
                'name' => 'linzh'
            ],
            [
                'id' => '2',
                'name' => '中文加char'
            ],
        ])->fetch());
    }
}